<?php

namespace App\Admin\Controllers;

use App\Models\TcmMedicineDetail;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TcmMedicineDetailController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TcmMedicineDetail(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('picture')->image('',50,50);
            //$grid->column('shareImg');
            //$grid->column('recipe');
            //$grid->column('manufacture');
            //$grid->column('characters');
            //$grid->column('indications');
            //$grid->column('usages');
            //$grid->column('cautions');
            //$grid->column('specification');
            //$grid->column('storage');
            //$grid->column('effects');
            //$grid->column('created_at');
            //$grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TcmMedicineDetail(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('shareImg')->image('',50,50);
            $show->field('picture')->image('',50,50);
			$show->field('recipe')->unescape()->as(function ($html) {
				return $html;
			});
            $show->field('manufacture');
            $show->field('characters');
            $show->field('indications');
            $show->field('usages');
            //$show->field('cautions');
            $show->field('specification');
            $show->field('storage');
            $show->field('effects')->json();
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TcmMedicineDetail(), function (Form $form) {

			$form->tab('基本信息', function (Form $form) {
				$form->display('id');
				$form->text('name');
				$form->image('picture')->uniqueName()->autoUpload()->saveFullUrl();
				$form->image('shareImg')->uniqueName()->autoUpload()->saveFullUrl();
				$form->list('effects')->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			$form->tab('处方', function (Form $form) {
				$form->editor('recipe');
			});
			$form->tab('功能和主治', function (Form $form) {
				$form->textarea('indications');
			});
			$form->tab('性状', function (Form $form) {
				$form->textarea('characters');
			});
			$form->tab('用法与用量', function (Form $form) {
				$form->textarea('usages');
			});

			$form->tab('规格', function (Form $form) {
				$form->textarea('specification');
			});
			$form->tab('贮藏', function (Form $form) {
				$form->textarea('storage');
			});
			$form->tab('制法', function (Form $form) {
				$form->textarea('manufacture');
			});
      
            //$form->text('cautions');
            
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
